/**
 * 
 */
package com.nwpusp.controller.actions;

import com.nwpusp.model.GameModel;
import com.nwpusp.model.characters.GameCharacter;
import com.nwpusp.model.players.GameRecord;
import com.nwpusp.model.players.Player;
import com.nwpusp.model.players.PlayerManager;
import com.nwpusp.model.session.ConnectionId;

/**
 * @author JustinCao
 *
 */
public class PlayerAddAction extends PlayerAction {
	private GameCharacter ch = null;
	private GameRecord record = null;
	private String playerName = "";
	private Player.PlayerStatus sts;
	
	public PlayerAddAction(String playerName, ConnectionId cid, GameCharacter ch, GameRecord record, Player.PlayerStatus sts) {
		super(cid);
		this.ch = ch;
		this.record = record;
		this.playerName = playerName;
		this.sts = sts;
	}
	
	@Override
	public String toString() {
		return "Add a "  + ch.toString() + ", its cid is " + Long.toString(cid.getCid());
	}
	
	@Override
	public void Invoke(GameModel m) {
		PlayerManager pm = m.getPlayerManager();
		GameCharacter oldCh = pm.addPlayer(cid, playerName, ch, record, sts);
		if(oldCh != null) {
			m.getScenario().removeCharacter(oldCh);
		}
		m.getScenario().addCharacter(ch);
	}
}
